#include<iostream>
using namespace std;
const int N = 1e5 + 10, M = 2 * N;
int dis[N];
int h[N], e[M], ne[M], idx;
int n, m;
void add(int a, int b)
{
	e[idx] = b;
	ne[idx] = h[a];
	h[a] = idx++;
}
void dfs(int u, int father, int v)
{
	dis[u] = v;
	for (int i = h[u]; ~i; i = ne[i]) {
		int j = e[i];
		if (j != father) {
			dfs(j, u, v + 1);
		}
	}
}
int main()
{
	cin >> n >> m;
	memset(h, -1, sizeof(h));
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		add(a, b);
		add(b, a);
	}
	dfs(1, -1, 0);
	int u = 1;
	for (int i = 1; i <= n; i++) {
		if (dis[u] < dis[i]) {
			u = i;
		}
	}
	dfs(u, -1, 0);
	for (int i = 1; i <= n; i++) {
		if (dis[u] < dis[i]) {
			u = i;
		}
	}
	cout << dis[u] << endl;
	return 0;
}